package com.sgb.zhaocai.widget;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.sgb.zhaocai.R;
import com.sgb.zhaocai.entity.PublishListBean;
import com.swgk.core.customview.ItemInputTextView;
import java.util.List;

/**
 * Created by：冯齐 on 2021/1/28 17:42
 * Description：
 */
public class SourcesFundDialog {

    private static RecyclerView listView;
    private static SourcesFundAdapter sourcesFundAdapter;

    public static void showBottomDialog(List<PublishListBean> tabellist, ItemInputTextView textView, Context context) {
        final Dialog dialog = new Dialog(context, R.style.DialogTheme);
        //2、设置布局
        View view = View.inflate(context, R.layout.zc_sources_fund_view, null);
        listView = view.findViewById(R.id.listView);
        dialog.setContentView(view);
        Window window = dialog.getWindow();
        //设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        //设置弹出动画
        window.setWindowAnimations(R.style.ActionSheetDialogAnimation);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        dialog.show();
        //取消
        dialog.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        //确定
        dialog.findViewById(R.id.determine).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < sourcesFundAdapter.getDatas().size(); i++) {
                    if (sourcesFundAdapter.getDatas().get(i).isSelected()){
                        sb.append(sourcesFundAdapter.getDatas().get(i).getName()).append(",");
                    }
                }
                if (!TextUtils.isEmpty(sb.toString())){
                    String str = sb.substring(0, sb.toString().length() - 1);
                    textView.setContent(str);
                }
                dialog.dismiss();
            }
        });
        sourcesFundAdapter = new SourcesFundAdapter(context, tabellist);
        listView.setLayoutManager(new LinearLayoutManager(context));
        listView.setAdapter(sourcesFundAdapter);
    }

}
